package com.numberone.tools;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 * ClassName: FileUploadInterceptor
 * Description:
 * @author 郑智聪
 * @date 2019年3月27日 下午14:06:53
 */
@Component
public class TokenInterceptor implements HandlerInterceptor {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	/**
	 * 视图渲染之后的操作
	 */
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) {

	}

	/**
	 * 处理请求完成后视图渲染之前的处理操作
	 */
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) {

	}

	/**
	 * 进入controller层之前拦截请求
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) {

		boolean ret = false;
		final String url = request.getRequestURI();
        if (url != null) {
            try {
				logger.info("请求的地址为"+url);
				/*boolean check = "/Weixin/".equals(url)||url.contains(".js")||url.contains(".json")||url.contains(".css")
						|| url.contains(".jpg")||url.contains(".ttf")||url.contains(".woff")||url.contains(".png")
						||url.contains("login")||url.contains("/Weixin/check/findByPage.shtml")||url.contains("/Weixin/form.html")
						||url.contains("insert")||url.contains("delete")||url.contains("update")||url.contains("changePwd")
						||url.contains("/Weixin/list.html")|| url.contains("/Weixin/check/findCheckById";
				if(check){
					ret = true;
				}*/
				ret=true;
			} catch (IllegalArgumentException e) {
            	 ret = false;
            } 
        } else {
			ret = false;
        }
        return  ret;
	}
}
